//   Copyright [SkyOS] [mrblond@skyhack.com.ar]
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.

#ifndef MEMORYMANAGER_HPP_
#define MEMORYMANAGER_HPP_

#include <type.hpp>

namespace Memory
{

/**
 * <br>MemoryManager</br> es la interface para
 * asignar o liberar memoria global ya sea fisica
 * o virtual.
 *
 * @author mrblond@skyhack.com.ar
 */
class MemoryManager
{
public:
	/**
	 * TotalMemory - The amount of memory that is present in the system.
	 */
	MemoryManager( uSizeT TotalMemory ) : usedMemory(0), virtualTotalMemory(0), virtualUsedMemory(0) {
		totalMemory = TotalMemory;
	}
	/**
	 * Release and clean all the memory used by the system.
	 */
	virtual ~MemoryManager();
	/**
	 * Allocate physical memory.
	 *
	 * lpMemorySrc    - Buffer that hold the address where we allocate the memory.
	 * dwStartMemory  - Addr to start looking free memory.
	 * dwMemoryLength - Length of the memory to allocate.
	 * @return	TRUE if the memory was allocated SUCCESFULL.
	 */
	virtual uBool phyAllocMemory(puPointerHolder lpMemorySrc,uSizeT dwStartMemory,uSizeT dwMemoryLength) = 0;
	/**
	 * Free physical memory.
	 *
	 * lpMemorySrc - Addr where we wanna free.
	 * @return TRUE if the memory was free SUCCESFULL.
	 */
	virtual uBool phyFreeMemory(puPointerHolder lpMemorySrc) = 0;
	/**
	 * Allocate MMU memory. @see Virtualization
	 *
	 * lpMemorySrc    - Buffer that hold the address where we allocate the memory.
	 * dwStartMemory  - Addr to start looking free memory.
	 * dwMemoryLength - Length of the memory to allocate.
	 * @return	TRUE if the memory was allocated SUCCESFULL.
	 */
	virtual uBool mmuAllocMemory(puPointerHolder lpMemorySrc, uSizeT dwStartMemory, uSizeT dwMemoryLength) = 0;
	/**
	 * Free MMU memory. @see Virtualization
	 *
	 * lpMemorySrc - Addr where we wanna free.
	 * @return TRUE if the memory was free SUCCESFULL.
	 */
	virtual uBool mmuFreeMemory(puPointerHolder lpMemorySrc) = 0;
	/**
	 * @return Total KB memory
	 */
	inline uSizeT getTotalMemory() const {
		return totalMemory;
	}
	/**
	 * @return Free KB memory
	 */
	inline uSizeT getFreeMemory() const {
		return usedMemory;
	}
	/**
	 * @return Total Virtual KB memory
	 */	
	inline uSizeT getTotalVirtualMemory() const {
		return virtualTotalMemory;
	}
	/**
	 * @return Free Virtual KB memory
	 */
	inline uSizeT getFreeVirtualMemory() const {
		return virtualUsedMemory;
	}
	
protected:
	uSizeT  totalMemory, usedMemory;
	uSizeT	virtualTotalMemory, virtualUsedMemory;
};

}	// namespace: Memory

#endif /* MEMORYMANAGER_HPP_ */
